package com.chen;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.nio.file.Paths;
import java.util.Collections;

public class MPGenerator {
    public static void main(String[] args) {
        FastAutoGenerator.create("jdbc:mysql://10.211.55.100:3306/social", "root", "1234")
                .globalConfig(builder -> builder
                        .author("chen")
                        .outputDir(Paths.get(System.getProperty("user.dir")) + "/common/src/main/java")
                        .commentDate("yyyy-MM-dd")
                )
                .packageConfig(builder -> builder
                        .parent("com.chen.webuser")
                        .entity("entity")
                        .mapper("mapper")
                        .service("service")
                        .serviceImpl("service.impl")
                        .pathInfo(Collections.singletonMap(
                                OutputFile.xml,
                                System.getProperty("user.dir") + "/common/src/main/resources/mapper"
                        ))
                )
                .strategyConfig(builder -> builder
                        .addInclude("dynamic")  //告诉mp需要生成那张表
                        .entityBuilder().enableLombok()//  开启 Lombok 模式
                        .enableTableFieldAnnotation() //生成 @TableField 等注解
                        .serviceBuilder().formatServiceFileName("%sService")
                        .mapperBuilder().enableMapperAnnotation() //带有mapper注解
                        .controllerBuilder().enableRestStyle() //开启rest风格
                )
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }


}
